package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {
    public static final String EMPLOYEE_IN_SESSION="EMPLOYEE_IN_SESSION";
    public static final String EXPRESSION_IN_SESSION="EXPRESSION_IN_SESSION";
    public static HttpServletRequest getRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }
    public static HttpSession getSession(){
        return getRequest().getSession();
    }
    public static void setEmployee(Employee employee){
       getSession().setAttribute(EMPLOYEE_IN_SESSION, employee);
    }
    public static Employee getEmployee(){
        return (Employee) getSession().getAttribute(EMPLOYEE_IN_SESSION);
    }

    public static void setExpression(List<String> expression) {
        getSession().setAttribute(EXPRESSION_IN_SESSION,expression);
    }
    public static List<String> getExpressions(){
        return  ((List<String>) getSession().getAttribute(EXPRESSION_IN_SESSION));
    }

}

